<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var p = new Promise(function(resolve,reject){
        setTimeout(function(){
            resolve(1);
        },2000)
    })

    /* console.log(p);
    p.then(function(num){
        console.log("callback1:", num);
        return 2;
    }).then(function(num){
        dddd;
        console.log("callback2:", num);
        return 3;
    }).then(function(num){
        // dddd;
        console.log("callback3:" , num);
    }).catch(function(err){
        console.log(err);
    }) */

    p.then(num => {
        console.log("callback1:", num);
        return randNum();
    }).then(num => {
        // aaaa;
        console.log("callback2:", num);
        return randNum();
    }).then(num =>{
        // aaaa;
        console.log("callback3:" , num);
    }).catch(err => console.log(err))


    function randNum(max = 100) { // 调用此方法  等待1s 随机生成一个数  => 返回Promise实例(默认进行中)
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                var num = Math.round(Math.random() * max);
                resolve(num);
            }, 1000)
        })
    }
</script>
</html>